package com.skyolder.milkbee.service;

import com.skyolder.milkbee.domain.Advertisement;
import com.skyolder.milkbee.repository.AdvertisementRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;

import javax.inject.Inject;
import java.util.List;

/**
 * Service Implementation for managing Advertisement.
 */
@Service
@Transactional
public class AdvertisementService {

    private final Logger log = LoggerFactory.getLogger(AdvertisementService.class);
    
    @Inject
    private AdvertisementRepository advertisementRepository;

    /**
     * Save a advertisement.
     *
     * @param advertisement the entity to save
     * @return the persisted entity
     */
    public Advertisement save(Advertisement advertisement) {
        log.debug("Request to save Advertisement : {}", advertisement);
        Advertisement result = advertisementRepository.save(advertisement);
        return result;
    }

    /**
     *  Get all the advertisements.
     *  
     *  @param pageable the pagination information
     *  @return the list of entities
     */
    @Transactional(readOnly = true) 
    public Page<Advertisement> findAll(Pageable pageable) {
        log.debug("Request to get all Advertisements");
        Page<Advertisement> result = advertisementRepository.findAll(pageable);
        return result;
    }

    /**
     *  Get one advertisement by id.
     *
     *  @param id the id of the entity
     *  @return the entity
     */
    @Transactional(readOnly = true) 
    public Advertisement findOne(Long id) {
        log.debug("Request to get Advertisement : {}", id);
        Advertisement advertisement = advertisementRepository.findOne(id);
        return advertisement;
    }

    /**
     *  Delete the  advertisement by id.
     *
     *  @param id the id of the entity
     */
    public void delete(Long id) {
        log.debug("Request to delete Advertisement : {}", id);
        advertisementRepository.delete(id);
    }
    @Transactional(readOnly = true) 
	public Page<Advertisement> queryByCategory(Long categoryId, Pageable pageable) {
		return advertisementRepository.queryByCategory(categoryId,pageable);
	}

	public Page<Advertisement> queryByPrematurity(Pageable pageable) {
		return advertisementRepository.queryByPrematurity(pageable);
	}

	public Page<Advertisement> queryByOnline(Pageable pageable) {
		return advertisementRepository.queryByOnline(pageable);
	}

	public Page<Advertisement> queryByExpire(Pageable pageable) {
		return advertisementRepository.queryByExpire(pageable);
	}
}
